package com.boot.unity.api.modules.training.service.impl;

import com.boot.unity.api.common.Result;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.boot.unity.api.modules.training.service.CoachService;
import com.boot.unity.api.modules.training.dao.CoachDao;
import com.boot.unity.api.modules.training.entity.Coach;
/**
 * @author anonymous
 *
 * @create 2020-06-06 22:07:11
 */
@Service
@AllArgsConstructor
public class CoachServiceImpl implements CoachService {
    private final CoachDao coachDao;

    @Override
    public Result save(Coach coach) {
        String inscode = coach.getInscode();
        String coachnum = coach.getCoachnum();
        Coach c = coachDao.getByInscodeAndCoachnum(inscode,coachnum);
        int num;
        if (c == null){
            num = coachDao.save(coach);
        }else {
            num = coachDao.updateByInscodeAndCoachnum(coach);
        }
        if (num > 0){
            return Result.success();
        }
        return Result.fail();
    }

    @Override
    public Result deleteByCoachnum(String coachnum) {
        int num = coachDao.deleteByCoachnum(coachnum);
        if (num > 0){
            return Result.success();
        }
        return Result.fail();
    }
}
